#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){
    
//    ofSetFrameRate(19);
    
    bounce = -0.75;
    
    circPoint.x = ofGetWidth()/2;
    circPoint.y = ofGetHeight()/10;
    
    mousePoint.set(0,0);
    
    vel.set(0, 0);
    
    acel.set(0, 0.0098);
    
    dir.set(0, -1);
    dir.normalize();
    
    thrust = 0;
}

//--------------------------------------------------------------
void testApp::update(){
    
    if(!thrust){
        circPoint += vel;

        vel += acel;
    
//      BOUNCING BALL
        if(circPoint.y > ofGetHeight()){
            circPoint.y -= vel.y;
            vel.y *= bounce;
        }
    
        if(circPoint.x > ofGetWidth() || circPoint.x < 0){
            circPoint.x -= vel.x;
            vel.x *= bounce;
        }
    }
    
    dir = (mousePoint - circPoint).normalize();
    
    if(ofGetKeyPressed(32)){
        thrust = 1;
        vel = dir * thrust;
    } else {
        thrust = 0;
    }
    
    circPoint += dir * thrust;
    
}

//--------------------------------------------------------------
void testApp::draw(){
    ofRect(circPoint, 10,10);
}

//--------------------------------------------------------------
void testApp::keyPressed(int key){
}

//--------------------------------------------------------------
void testApp::keyReleased(int key){
}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
    
    mousePoint.set(x,y);
}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){ 

}